#ifndef Conference_ControlMessage_H
#define Conference_ControlMessage_H

#include <memory>
#include <vector>

#include "FastJsoncpp.h"
#include "SerializableObject.h"
#include "json/value.h"
class ControlMessage : public SerializableObject
{
    SERIALIZABLE_OBJECT_D(ControlMessage)
   public:
    using Ptr = std::shared_ptr<ControlMessage>;
    ControlMessage();

    const std::string& getConferenceId() const;
    const std::string& getNumber() const;
    const std::string& getEvent() const;
    int getSequence() const;
    const std::string& getContent() const;
    const Json::Value& getOrigRequestData() const;
    friend std::ostream& operator<<(std::ostream& os, const ControlMessage::Ptr& obj)
    {
        if (!obj)
        {
            return os << "control{nullptr}";
        }
        os << obj->_event << "{confId=" << obj->_conferenceId
           << ", number=" << obj->_number << "}";
        return os;
    }

    template <class T>
    std::shared_ptr<T> upgrade()
    {
        std::shared_ptr<T> up = std::make_shared<T>();
        if (!up->_parse(_origJson))
            return nullptr;

        up->_number = _number;
        up->_content = _content;
        up->_event = _event;
        up->_sequence = _sequence;
        up->_conferenceId = _conferenceId;
        up->_origJson = _origJson;

        return up;
    }

   public:
    virtual bool _parse(const Json::Value& message) { return true; };

   protected:
    std::string _conferenceId;
    std::string _number;
    std::string _content;
    std::string _event;
    int _sequence = -1;
    Json::Value _origJson;
};

#endif
